function [f,y] = objective_fun(theta2,sj,deltaold,v,x2,p,QI,ind_market,A1,xtilde,ztilde,W,sales_tax)
ya=computey(theta2,sj,v,x2,p,QI,ind_market,A1,deltaold,sales_tax);
y=ya;
temp2=inv(xtilde'*ztilde*W*ztilde'*xtilde)*xtilde'*ztilde*W*ztilde'*y;
resid=y-xtilde*temp2; 
vect=ztilde'*resid;
f=vect'*W*vect;
if isreal(y)==0;
    f=1e+009;     % if negative mc for some product, log(mc) would have complex elements - objective not defined; set arbitrarily large value
end;



